import { Controller, Get, Post, Body, Patch, Param, Delete, Res, UseGuards, Query } from '@nestjs/common';
import { ChatService } from './chat.service';
import { AuthGuard } from '@nestjs/passport';
import { CreateChatDto } from './dto/create-chat.dto';
import { UpdateChatDto } from './dto/update-chat.dto';
import { CurrentUser } from '../auth/user.decorator';
@Controller('api/chat')
export class ChatController {
  constructor(private readonly chatService: ChatService) {}

  @UseGuards(AuthGuard('jwt'))
  @Get()
  findAll(@Res() response:any, @CurrentUser() user: any, @Query() payload:any) {
    return this.chatService.findAll(response,user,payload);
  }

  @Post()
  create(@Body() createChatDto: CreateChatDto,@Res() response:any, @CurrentUser() user: any) {
    return this.chatService.create(createChatDto,response,user);
  }

  @Delete()
  deleteAll() {
    return this.chatService.delete(null);
  }

  @Get('conversation')
  getConversations(@Res() response:any, @CurrentUser() user: any) {
    return this.chatService.getConversations(response,user);
  }

  @UseGuards(AuthGuard('jwt'))
  @Delete('conversation')
  deleteConversation(@Query() payload: any) {
    return this.chatService.deleteConversation(+payload.conversationId);
  }

  @Delete(':id')
  deleteOne(@Param('id') id: string) {
    return this.chatService.delete(id);
  }
}
